<extend name="Layout::index"/>
<block name="title"><title>主页</title></block>
<block name="main">
    <div class="panel panel-info">
        <div class="panel-heading">
            相册系统
        </div>
            <div class="panel-body">
                <empty name="list">
                    <div style="margin-top:150px;font-size:50px;margin-left:35%;height:200px;">没有相册</div>
                <else />
                <foreach name="list" item="val">
                    <div class="col-xs-12 col-sm-6 col-md-4" >
                            <div class="thumbnail">
                                <img src="__ROOT__{$val['face']}" alt="...">
                                <div class="caption">
                                    <h3>{$val['name']}</h3>
                                    <p><a  class="btn btn-primary" role="button" pid="{$val['id']}" >进入相册</a> <a  class="btn btn-default" role="button" data-toggle="modal" data-target="#myModal4" ><input type="hidden" value="{$val['id']}">添加图片</a></p>
                                </div>
                            </div>
                    </div>
                </foreach>
                </empty>
            </div>
    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">Album</h4>
                </div>
                <div class="modal-body">
                    <form method="post" action="{:U('Index/doalbum')}" enctype="multipart/form-data">
                        <div class="form-group">
                            <label for="exampleInputEmail1">相册名</label>
                            <input type="text" class="form-control" id="exampleInputEmail1" name="name" >
                        </div>
                        <div class="form-group">
                            <label for="exampleInputFile">文件</label>
                            <input type="file" id="exampleInputFile" name="pic">
                        </div>
                        <button type="submit" class="btn btn-primary">提交</button>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="myModal4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">Photo</h4>
                </div>
                <div class="modal-body">
                    <form method="post" action="{:U('Index/photo')}" enctype="multipart/form-data" >
                        <input type="hidden" id="pict" name="aid"/>
                        <div class="form-group">
                            <label for="exampleInputFile">文件</label>
                            <input type="file" id="exampleInputFile1" name="pic">
                        </div>
                        <button type="submit" class="btn btn-primary" >提交</button>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
    <script>
        $('.panel-body').find('[pid]').click(function ()
        {
              var pid=($(this).attr('pid'));
              $.ajax({
                type:'POST',
                url:"{:U('Index/intophoto')}",
                data:{'pid':pid},
                datatype:'string',
                success:function(msg){
                 $('.panel-heading').parent().replaceWith(msg);
                }
            })
        })
        $('.panel-body').find('[pid]').next().click(function () {
            var bid = ($(this).find('[value]').attr('value'));
            $('#pict').val(bid);
        })
        function func() {
            var bid = $('.panel-body').find('[aid]').attr('aid');
            $('#pict').val(bid);
        }
    </script>
</block>
